#include "cust_comdef.h"
#include "cust_hif.h"
#include "cust_usb_drv.h"
#include "cust_cmr_drv.h"
#include "cust_sd_drv.h"

int reg_read_write()
{
	int ret,io_val;

//IOU internal register read write
	ret=read_host_internal(HIF_INT_MASK);
	write_host_internal(HIF_INT_MASK, 0);
	ret=read_host_internal(HIF_INT_MASK);
	write_host_internal(HIF_INT_MASK, 0x33cc);
	ret=read_host_internal(HIF_INT_MASK);

//USB IF register read write
	io_val=CUST_IO_INW(USB_INT_MASK);
	CUST_IO_OUTW(USB_INT_MASK, 0);
	io_val=CUST_IO_INW(USB_INT_MASK);
	CUST_IO_OUTW(USB_INT_MASK, 0x55aa33cc);
	io_val=CUST_IO_INW(USB_INT_MASK);

//USB IP register read write
	io_val=CUST_IO_INB(APP_IMASK);
	CUST_IO_OUTB(APP_IMASK, 0);
	io_val=CUST_IO_INB(APP_IMASK);
	CUST_IO_OUTB(APP_IMASK, 0x55);
	io_val+=CUST_IO_INB(APP_IMASK);

//USB IP register read 16-bit
	ret+=MA_INH(APP_EP0_VALUE);
	ret+=MA_INH(APP_EP0_INDEX);

//cmif register read write
	io_val=CUST_IO_INW(CMR_INT_MASK);
	CUST_IO_OUTW(CMR_INT_MASK, 0);
	io_val=CUST_IO_INW(CMR_INT_MASK);
	CUST_IO_OUTW(CMR_INT_MASK, 0x55aa33cc);
	io_val=CUST_IO_INW(CMR_INT_MASK);

//SD register read write
	io_val=CUST_IO_INW(HW_SD_TIMEOUT);
	CUST_IO_OUTW(HW_SD_TIMEOUT, 0x12345678);
	io_val=CUST_IO_INW(HW_SD_TIMEOUT);
	CUST_IO_OUTW(HW_SD_TIMEOUT, 0x87654321);
	io_val=CUST_IO_INW(HW_SD_TIMEOUT);
	
	return ret+io_val;
}

#ifndef _TEST_PATTERN_
int test_hif()
#else
int c_main()
#endif
{
	CUST_U16 status;
	
	while (1)
	{
		// TP Enable chip clock	
		status=inpb(HIF_TP_RW_CMD);
		outpb(HIF_TP_RW_CMD,0);
		outpb(HIF_TP_RW_CMD,0xff);
		status=inpb(HIF_TP_RW_CMD);

		reg_read_write();
	}
}

